package com.jinghua.treatment.controller;

import com.jinghua.treatment.common.exception.BizException;
import com.jinghua.treatment.entity.SysDoctor;
import com.jinghua.treatment.entity.SysPatient;
import com.jinghua.treatment.service.SysDoctorService;
import com.jinghua.treatment.service.SysPatientService;
import com.jinghua.treatment.tools.PropertyUtil;
import com.jinghua.treatment.wechat.biz.WechatBiz;
import com.jinghua.treatment.wechat.entity.Article;
import com.jinghua.treatment.wechat.entity.JSONNewsEntity;
import com.jinghua.treatment.wechat.entity.News;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 问诊单控制器
 * Created by 王兴光 on 2018/3/24.
 */
@Controller
@RequestMapping("/inquiry")
public class SysInquiryController {
    @Resource
    private  WechatBiz wechatBiz;

   /* *//**
     * 问诊单service接口
     *//*
    @Resource
    private SysInquiryService inquiryService;

    @Resource
    private SysPatientService sysPatientService;
    @Resource
    private SysDoctorService sysDoctorService;

    @ApiOperation(value="发送问诊单给患者")
    @RequestMapping(value="/addInquiry",method= RequestMethod.POST)
    @ResponseBody
    public JSONResult addInquiry(SysInquiry inquiry){
        inquiry.setUuid(IDGenerator.uuid());
        inquiry.setCreationdate(new Date());
        return new JSONResult(GlobalConstant.SUCCESS_CODE,"添加问诊单信息",inquiryService.addInquiry(inquiry));
    }

    @ApiOperation(value="发送问诊单给患者")
    @GetMapping(value="/sendInquiry")
    @ResponseBody
    public String sendInquiry(Integer patientId,Integer doctorId,Integer inquiryId){
        if(StringUtils.isEmpty(patientId)||StringUtils.isEmpty(doctorId)||StringUtils.isEmpty(inquiryId))
            throw  new BizException("缺失参数");

        SysPatient sysPatient = sysPatientService.selectById(patientId);
        SysDoctor sysDoctor = sysDoctorService.findById(doctorId);
        if(sysPatient!=null&&sysDoctor!=null){
            JSONNewsEntity jsonNewsEntity = new JSONNewsEntity(sysPatient.getWechat(),"news");
            News news = new News();
            jsonNewsEntity.setNews(news);
//String title, String description, String url, String picurl
            Article main = new Article(sysPatient.getPatientname()+","+sysDoctor.getDoctorname()+"给你发 来一份问诊单，请认真填写",
            "填写问诊单",
            PropertyUtil.getConfig("app.server")+"/mod-page/inquiry/inquiry-for-send.html?patientId="+patientId+"&doctorId="+doctorId+"&"+"inquiryId="+inquiryId,
                    PropertyUtil.getConfig("app.server")+"/mod-page/images/wechat/doctor_inquiry_guider.jpg");
            news.getArticles().add(main);

            Article sub = new Article("问诊单填写指南",
                    "填写问诊单",
                    PropertyUtil.getConfig("app.server")+"/mod-page/inquiry/inquiry-guider.html",
                    PropertyUtil.getConfig("app.server")+"/mod-page/images/wechat/howtofillform.png");
            news.getArticles().add(sub);

            wechatBiz.sendNews(jsonNewsEntity);
        }

        return  null;
    }
*/
 @Resource
    private SysPatientService sysPatientService;
    @Resource
    private SysDoctorService sysDoctorService;

    @ApiOperation(value="发送问诊单给患者")
    @GetMapping(value="/sendInquiry")
    @ResponseBody
    public String sendInquiry(Integer patientId,Integer doctorId,Integer inquiryId){
        if(StringUtils.isEmpty(patientId)||StringUtils.isEmpty(doctorId)||StringUtils.isEmpty(inquiryId))
            throw  new BizException("缺失参数");

        SysPatient sysPatient = sysPatientService.selectById(patientId);
        SysDoctor sysDoctor = sysDoctorService.findById(doctorId);
        if(sysPatient!=null&&sysDoctor!=null){
            JSONNewsEntity jsonNewsEntity = new JSONNewsEntity(sysPatient.getWechat(),"news");
            News news = new News();
            jsonNewsEntity.setNews(news);
//String title, String description, String url, String picurl
            Article main = new Article(sysPatient.getPatientname()+","+sysDoctor.getDoctorname()+"给你发 来一份问诊单，请认真填写",
            "填写问诊单",
            PropertyUtil.getConfig("app.server")+"/mod-page/inquiry/inquiry-for-send.html?patientId="+patientId+"&doctorId="+doctorId+"&"+"inquiryId="+inquiryId,
                    PropertyUtil.getConfig("app.server")+"/mod-page/images/wechat/doctor_inquiry_guider.jpg");
            news.getArticles().add(main);

            Article sub = new Article("问诊单填写指南",
                    "填写问诊单",
                    PropertyUtil.getConfig("app.server")+"/mod-page/inquiry/inquiry-guider.html",
                    PropertyUtil.getConfig("app.server")+"/mod-page/images/wechat/howtofillform.png");
            news.getArticles().add(sub);

            wechatBiz.sendNews(jsonNewsEntity);
        }

        return  null;
    }

}
